import store from '@/store'
import extend from 'extend'
import app from '../../assets/js/app/index.js'
import firstPage from './firstPage'
import secondPage from './secondPage'
let cashData = []
let mockConnection = false
const handleData = path => {
  cashData = [firstPage, secondPage]
  let dataSet = extend(
    true,
    {},
    cashData.find(item => item.path == path)
  )
  store.commit('setDataSet', dataSet)
  mockConnection = true
  app.$emit('dataReady')
  // window.store = store
}
const init = (path = '/') => {
  if (mockConnection) {
    let dataSet = extend(
      true,
      {},
      cashData.find(item => item.path == path)
    )
    store.commit('setDataSet', dataSet)
  } else {
    handleData(path)
  }
  app.log('mock init')
}
const destroy = () => {
  mockConnection = false
  cashData = []
  app.log('mock destroy')
}
export { init, destroy }
